<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                template="./../template/AdminTemplate.xhtml">

    <ui:define name="contentInsert">
        
        <h3>Stakeholder Billing</h3>
        <p:panel id="panel" >
            <br/>
            <h4>View Billing Records</h4>

            <h:form>
                Enter Year: &nbsp;                                             
                <p:inputText id="quantityInput" value="#{billingMB.selectedYear}">
                    <f:validateLongRange minimum="1"/> 
                </p:inputText> 

                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

                Select Month: &nbsp;
                <h:selectOneMenu value="#{billingMB.selectedMonth}">  
                    <f:selectItem itemLabel="JAN" itemValue="0" />
                    <f:selectItem itemLabel="FEB" itemValue="1" />  
                    <f:selectItem itemLabel="MAR" itemValue="2" />
                    <f:selectItem itemLabel="APR" itemValue="3" />  
                    <f:selectItem itemLabel="MAY" itemValue="4" />  
                    <f:selectItem itemLabel="JUN" itemValue="5" />  
                    <f:selectItem itemLabel="JUL" itemValue="6" />  
                    <f:selectItem itemLabel="AUG" itemValue="7" />  
                    <f:selectItem itemLabel="SEP" itemValue="8" />  
                    <f:selectItem itemLabel="OCT" itemValue="9" />  
                    <f:selectItem itemLabel="NOV" itemValue="10" />  
                    <f:selectItem itemLabel="DEC" itemValue="11" />  
                </h:selectOneMenu> 


                &nbsp;&nbsp;

                Exclude Paid Bills: &nbsp;
                <h:selectBooleanCheckbox value="#{billingMB.excludePaidBills}" />
                <br/>
                <p:commandButton value="Retrieve Bills" action="#{billingMB.retrieveBillsByMonth()}" ajax="false"/>
            </h:form>

            <h:form>
                <p:dataTable value="#{billingMB.retrieveBillsByMonth()}" var="o" paginator="true" rows="20"
                             emptyMessage="No bills to display"
                             onRowSelectUpdate="panel"
                             selection="#{billingMB.selectedBill}"
                             selectionMode="single"
                             >
                    <p:column style="width: 10%">
                        <f:facet name="header">ID</f:facet>
                                        #{o.id}
                    </p:column>

                    <p:column style="width: 20%">
                        <f:facet name="header">Stakeholder Debtor</f:facet>
                                        #{o.stakeHolderName}
                    </p:column>

                    <p:column style="width: 15%">
                        <f:facet name="header">Billing Date</f:facet>
                                        #{o.billDate}
                    </p:column>

                    <p:column style="width: 15%">
                        <f:facet name="header">Date of Payment</f:facet>
                                        #{o.paymentDate}
                    </p:column>

                </p:dataTable>
                Click on a row in the above table to get additional details about the bill shown below.
            </h:form>
            
                <br/>
                <br/>
            
            <h:form>
                <h4>Bill Details</h4>
                 <h:panelGrid columns="3">
                     <h5>Bill ID: &nbsp;</h5>                       <h:outputLabel value="#{billingMB.selectedBill.id}" />                                   <h:outputLabel value=" "/>   
                     <h5>Debtor: &nbsp;</h5>                        <h:outputLabel value="#{billingMB.selectedBill.stakeHolderName}" />                      <h:outputLabel value=" "/>
                     <h5>Date of Bill: &nbsp;</h5>                  <h:outputLabel value="#{billingMB.selectedBill.billDate}" />                             <h:outputLabel value=" "/>
                     <h:outputLabel value=" "/> <h:outputLabel value=" "/> <h:outputLabel value=" "/>
                     <h:outputLabel value=" "/> <h:outputLabel value=" "/> <h:outputLabel value=" "/>
                     <h5>Subscription Fee: &nbsp;</h5>              <h:outputLabel value="#{billingMB.selectedBill.billSubscription}" />                     <h:outputLabel value=" " />
                     <h5>Transaction Analytics Fee: &nbsp;</h5>     <h:outputLabel value="#{billingMB.selectedBill.billMarketIntelligence}" />               <h:outputLabel value=" " />
                     <h5>Advertising Fee: &nbsp;</h5>               <h:outputLabel value="#{billingMB.selectedBill.billAdvertising}" />                      <h:outputLabel value=" " />
                     <h5>Total Bill Receivable: &nbsp;</h5>         <h:outputLabel value="#{billingMB.selectedBill.subTotal}" />                             <h:outputLabel value=" " /> 
                     <h5>Reimbursement: &nbsp;</h5>                 <h:outputLabel value="#{billingMB.selectedBill.reInbursement}" />                        <h:outputLabel value=" " /> 
                     <h:outputLabel value=" "/> <h:outputLabel value=" "/> <h:outputLabel value=" "/>
                     <h:outputLabel value=" "/> <h:outputLabel value=" "/> <h:outputLabel value=" "/>
                     <h5><b>#{billingMB.displayOverallSubtotal()}</b></h5>
                 </h:panelGrid>
                
                 <p:commandButton   value="Acknowledge this Bill as Paid" onclick="if (!confirm('Declare this bill as paid?')) return false"
                     action="#{billingMB.setBillAsPaid(billingMB.selectedBill.id)}" ajax="false">
                 </p:commandButton>      
            </h:form>
                
                <br/>
                <br/>
                
            <h:form>
                
                
            </h:form>
                
                
                <h:form>
                    <h3>Billing Summary</h3>
                    Generate a billing summary for a particular billing period (specific month of specific year) in PDF form.<br/>
                    NOTE: You are required to specify a stakeholder tier.
                    
                    <p:panel>
                        <p:ajaxStatus style="width:16px;height:16px;">
                            <f:facet name="start">
                                <h:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" />
                            </f:facet>
                            <f:facet name="complete">
                                <h:outputText value="" />
                            </f:facet>
                        </p:ajaxStatus>
                        <p:messages />

                        <h:panelGrid columns="3">
                            
                            <h:outputLabel for="year" value="Enter year: "/>
                            <p:inputText required="true" requiredMessage="Year is requied!" id="year" value="#{stakeholderAccountsManagerBean.year}">
                                <f:validateLongRange minimum="1"/> 
                            </p:inputText>
                            <p:message for="year"/>
                            
                            
                            <h:outputLabel for="month" value="Choose Month"/>          
                            <h:selectOneMenu id="month" value="#{stakeholderAccountsManagerBean.month1}">  
                                <f:selectItem itemLabel="JAN" itemValue="1" />
                                <f:selectItem itemLabel="FEB" itemValue="2" />  
                                <f:selectItem itemLabel="MAR" itemValue="3" />
                                <f:selectItem itemLabel="APR" itemValue="4" />  
                                <f:selectItem itemLabel="MAY" itemValue="5" />  
                                <f:selectItem itemLabel="JUN" itemValue="6" />  
                                <f:selectItem itemLabel="JUL" itemValue="7" />  
                                <f:selectItem itemLabel="AUG" itemValue="8" />  
                                <f:selectItem itemLabel="SEP" itemValue="9" />  
                                <f:selectItem itemLabel="OCT" itemValue="10" />  
                                <f:selectItem itemLabel="NOV" itemValue="11" />  
                                <f:selectItem itemLabel="DEC" itemValue="12" />  
                            </h:selectOneMenu>
                            <p:message for="month"/>
                               
                            
                            <h:outputLabel for="tier" value="Stakholder's Membership Tier: "/>
                            <h:selectOneMenu value="#{stakeholderAccountsManagerBean.stakeholderTier}">
                                <f:selectItems value="#{tierManagerBean.allTiers}" var="c" itemLabel="#{c.name}" itemValue="#{c.name}" />
                            </h:selectOneMenu>  

                        </h:panelGrid>
                        <br/>
                        <h:commandButton id="generateReport1" value="Generate Bill Summary" onclick="if (!confirm('Are you sure you want to generate bill summary?')) return false"
                                         action="#{stakeholderAccountsManagerBean.generateStakeholderBill(event)}"
                                         />
                    </p:panel>
                </h:form>
                
                <br/><br/>
                
                <h:form>
                    <h3>Billing Controls</h3>
                    <h:outputLabel value="#{billingMB.getBillingStatus()}" escape="false"></h:outputLabel>
                    <br/><br/>
                    Monthly billing is done at 00:00 hrs on the 3rd day of every month.<br/>
                    Demonstration billing is used for demonstration purposes and has a billing cycle of 30 seconds<br/>
                    instead of once every month. When demonstration billing is enabled, the actual monthly billing will be disabled.<br/>
                    <br/>
                    <h:form>
                        <p:commandButton action="#{billingMB.startBilling()}" value="Enable Billing" ajax="false"/>&nbsp;&nbsp;
                        <p:commandButton action="#{billingMB.stopBilling()}" value="Disable Billing" ajax="false"/>
                        <br/>
                        <p:commandButton action="#{billingMB.enableDemoBilling()}" value="Use Demo Billing" ajax="false"/>&nbsp;&nbsp;
                        <p:commandButton action="#{billingMB.disableDemoBilling()}" value="Switch back to Actual Billing" ajax="false"/>
                        <br/>
                    </h:form>
                </h:form>
                
                
                
                
                
                
                
                
                 

        </p:panel>
    </ui:define>
</ui:composition>

